import 'dart:io';

import 'package:get/get.dart';

import '../utils/utils.dart';




/// 基于GetX Controller基类，提供路由返回、loading、toast、log等基础功能
/// 所有controller应继承此类
class BaseController extends GetxController {
  @override
  void onInit() {
    super.onInit();
    logV('$runtimeType Init called');
  }

  @override
  void onClose() {
    super.onClose();
    logV('$runtimeType Close called');
  }

  @override
  void onReady() {
    super.onReady();
    logV('$runtimeType Ready called');
  }

  /// 路由返回
  void goBack<T>({
    T? result,
    bool closeOverlays = false,
    bool canPop = true,
    int? id,
  }) {
    Get.back(result: result, closeOverlays: closeOverlays, canPop: canPop, id: id);
  }

  /// 显示loading对话框
  Future<T?> showLoading<T>({String? msg, bool? backDismiss, bool? usePenetrate}) {
    return Utils.showLoading<T>(msg: msg, backDismiss: backDismiss, usePenetrate: usePenetrate);
  }

  /// 隐藏loading对话框
  Future<void> hideLoading() {
    return Utils.hideLoading();
  }

  /// 展示toast
  Future<void> showToast(String? msg) {
    return Utils.showToast(msg);
  }


  /// debug信息打印
  void logD(Object? object) {
    Utils.logD(object);
  }

  /// error信息打印
  void logE(Object? object, {StackTrace? stackTrace}) {
    Utils.logE(object, stackTrace: stackTrace);
  }

  /// verbose信息打印
  void logV(Object? object) {
    Utils.logI(object);
  }

  /// 退出APP
  void exitApp() {
    exit(0);
  }
}
